const express = require('express')
const router = express.Router()

// http://127.0.0.1/api/get?name=张智琦&age=18
router.get('/get', (req, res) => {
  res.send({
    status: 0,
    msg: '成功',
    data: req.query
  })
})

// http://127.0.0.1/api/get/path/777
router.get('/get/path/:id', (req, res) => {
  res.send({
    status: 0,
    msg: '成功',
    data: req.params
  })
})

// http://127.0.0.1/api/get/jsonp?callback=onSuccess&name=张智琦&age=18
router.get('/get/jsonp', (req, res) => {
  const callback = req.query.callback
  req.query.callback = undefined
  const data = {
    status: 0,
    msg: '成功',
    data: req.query
  }
  res.send(`${callback}(${JSON.stringify(data)})`)
})

module.exports = router
